package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizActivity;
import com.member.shop.domain.SysBizActivityUser;
import com.member.shop.service.ISysBizActivityUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 【参与活动用户】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-11-09
 **/
@RestController
@RequestMapping("/shop/activityUser")
public class SysBizActivityUserController extends BaseController {
    @Resource
    private ISysBizActivityUserService sysBizActivityUserService;
    private void setTenantId(SysBizActivityUser sysBizActivityUser) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizActivityUser.setTenantId(tenantId);
        }
    }
    /**
     * 查询参与活动用户列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizActivityUser sysBizActivityUser) {
        startPage();
        setTenantId(sysBizActivityUser);
        List<SysBizActivityUser> list = sysBizActivityUserService.selectSysBizActivityUserList(sysBizActivityUser);
        return getDataTable(list);
    }

    /**
     * 导出参与活动用户列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:export')")
    @Log(title = "参与活动用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizActivityUser sysBizActivityUser) {
        setTenantId(sysBizActivityUser);
        List<SysBizActivityUser> list = sysBizActivityUserService.selectSysBizActivityUserList(sysBizActivityUser);
        ExcelUtil<SysBizActivityUser> util = new ExcelUtil<SysBizActivityUser>(SysBizActivityUser. class);
        util.exportExcel(response, list, "参与活动用户数据");
    }

    /**
     * 获取参与活动用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizActivityUserService.selectSysBizActivityUserById(id));
    }

    /**
     * 新增参与活动用户
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:add')")
    @Log(title = "参与活动用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizActivityUser sysBizActivityUser) {
        return toAjax(sysBizActivityUserService.insertSysBizActivityUser(sysBizActivityUser));
    }

    /**
     * 修改参与活动用户
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:edit')")
    @Log(title = "参与活动用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizActivityUser sysBizActivityUser) {
        return toAjax(sysBizActivityUserService.updateSysBizActivityUser(sysBizActivityUser));
    }

    /**
     * 删除参与活动用户
     */
    @PreAuthorize("@ss.hasPermi('shop:activityUser:remove')")
    @Log(title = "参与活动用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizActivityUserService.deleteSysBizActivityUserByIds(ids));
    }
}
